home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVI_DVI1 / dvilj / c / dvimisc < prev    next >
Text File  |  1996-02-28  |  26KB  |  878 lines

  1. #include "dvilj.h"
  2.  
  3.  
  4.  
  5. /*-->AllDone*/
  6. /**********************************************************************/
  7. /****************************** AllDone  ******************************/
  8. /**********************************************************************/
  9. void
  10. AllDone(bool PFlag)
  11. {
  12. #ifdef TIMING
  13.     double  time;
  14. #endif
  15.  
  16.     if (DoublePage && (PageParity==1)) { /* Shall we go around again?*/
  17.         int k;
  18.         char    n[STRSIZE];
  19.  
  20.         if (PrintEmptyPages && EvenPage && Reverse && PrintFirstPart) {
  21.             WouldPrint ++;
  22.             qfprintf(ERR_STREAM,"[EvenPage] ");
  23.             FormFeed();
  24.         }
  25. #ifdef LJ
  26.         Reverse = (bool)!Reverse;
  27. #endif
  28.         if (Reverse) {
  29.             if (!PFlag) {
  30.                FSEEK (dvifp, postambleptr, SEEK_SET);
  31.                (void) NoSignExtend(dvifp, 1);
  32.                ppagep = NoSignExtend(dvifp, 4);
  33.             }
  34.             FSEEK(dvifp, ppagep, SEEK_SET);
  35.         } else {
  36.             FSEEK(dvifp,  14l, SEEK_SET);
  37.         k = (int) NoSignExtend(dvifp, 1);
  38.         GetBytes(dvifp, n, k);
  39.         }
  40.  
  41.     if (PrintSecondPart) {
  42.       if (PrintFirstPart) {
  43.         qfprintf(ERR_STREAM,"\n----------------------starting second pass\n");
  44. #ifdef LJ
  45.         EMIT(EMTO, "\033&l2H"); EMFLUSH; /* Manual Feed */
  46. #endif
  47. #ifdef IBM3812
  48.         PMPout(6,"\326\001\305\300\326\252");
  49.         /* set display; ring bell; stop; clear display */
  50.         PMPflush;
  51. #endif
  52.       }
  53.  
  54.       if (PrintEmptyPages && Reverse) {
  55.         if (ZeroPage) WouldPrint++;
  56.         if ((WouldPrint%2) == 1) {
  57.           qfprintf(ERR_STREAM,"[Padding] ");
  58.           FormFeed();
  59.         }
  60.       }
  61.       WouldPrint = 0;
  62.       if (PrintEmptyPages && !Reverse && ZeroPage) {
  63.         WouldPrint++;
  64.         qfprintf(ERR_STREAM,"[ZeroPage] ");
  65.         FormFeed();
  66.       }
  67.       PageParity = 0;
  68.       PrintPages = StartPrintPages;
  69.       return;
  70.     }
  71.     }
  72.  
  73.     if (EvenPage && DoublePage && !Reverse) WouldPrint++;
  74.  
  75.     if (PrintEmptyPages && DoublePage && PrintSecondPart) {
  76.         if (Reverse) {
  77.       if (ZeroPage) {
  78.             WouldPrint ++;
  79.             qfprintf(ERR_STREAM,"[ZeroPage] ");
  80.             FormFeed();
  81.       }
  82.         }
  83.         else if ((WouldPrint%2) != 0) {
  84.             qfprintf(ERR_STREAM,"[Padding] ");
  85.             FormFeed();
  86.         }
  87.     }
  88.  
  89. #ifdef IBM3812
  90.     PMPout(10, "\373\010PMP.init");  /* re-init printer  */
  91.     PMPflush;
  92.  
  93.     if (used_fontstorage > MAXFONTSTORAGE) {
  94.         Warning("\n\7used font_storage of %s: %ld Bytes (of %ld)\7",
  95.             PRINTER, (long)used_fontstorage, (long)MAXFONTSTORAGE);
  96.         Warning("Try to format file in separate runs!");
  97.     } else
  98.         qfprintf(ERR_STREAM,
  99.            "\nAll done, used font_storage of %s: %ld Bytes (of %ld)",
  100.              PRINTER, (long)used_fontstorage, (long)MAXFONTSTORAGE);
  101. #endif
  102. #ifdef LJ
  103.     qfprintf(ERR_STREAM, "\nAll done, used font_storage of %s: %ld Bytes",
  104.              PRINTER, (long)used_fontstorage);
  105. #ifdef LJ_RESIDENT_FONTS
  106.     qfprintf(ERR_STREAM, " + %d resident font%s", resident_count,
  107.              resident_count == 1 ? "" : "s");
  108. #endif
  109.     EMIT(EMTO, "\033E"); EMFLUSH;
  110. #ifdef LJ4
  111.     EMIT(EMTO, "\033%%-12345X"); EMFLUSH;  /* what does it? */
  112. #endif
  113.     if (PrintTestPage) {EMIT(EMTO, "\033z"); EMFLUSH;}
  114. #ifdef vms
  115.     /* last record is not flushed to file, unless it is completely filled */
  116.     for (kk = (int)((*outfp)->_cnt); kk > 0; --kk) write_byte(outfp,'\0');
  117.     fflush(outfp);
  118. #endif
  119. #endif
  120.  
  121.     if (!G_quiet) {
  122.         fprintf(ERR_STREAM,"\nDynamically allocated storage: %ld Bytes \n",
  123.                     (long)allocated_storage);
  124.         fprintf(ERR_STREAM,"%d characters downloaded as soft fonts\n", G_ncdl);
  125.  
  126. #ifdef TIMING
  127. #ifdef BSD_TIME_CALLS
  128.         ftime(&timebuffer);
  129.         time = (timebuffer.time + (float)(timebuffer.millitm)/1000.0)
  130.            - start_time;
  131. #else
  132.     gettimeofday(&Tp, NULL);
  133.     time = (Tp.tv_sec + (float)(Tp.tv_usec)/1000000.0) - start_time;
  134. #endif
  135.  
  136.         if (ndone > 0) {
  137.             fprintf(ERR_STREAM,
  138.            "Time of complete run: %.2f seconds, %d page(s), %.2f seconds/page",
  139.                       time, ndone, time / ndone);
  140.             fprintf(ERR_STREAM," (%.2f ppm)\n",(ndone * 60) / time);
  141.         }
  142.         fprintf(ERR_STREAM,"\n");
  143. #endif
  144.     }
  145.     CloseFiles();
  146.     exit(G_errenc);
  147. }
  148.  
  149.  
  150. /*-->DoSpecial*/
  151. /*********************************************************************/
  152. /*****************************  DoSpecial  ***************************/
  153. /*********************************************************************/
  154.  
  155. KeyDesc KeyTab[] = {
  156.     { "file", String },
  157.     { "orientation", Integer},
  158.     { "resetpoints", String},
  159.     { "defpoint", String},
  160.     { "fill", String},
  161.     { "gray", Integer},
  162.     { "pattern", Integer},
  163.     { "hpfile", String},
  164.    /*,
  165.              {"hsize", Dimension},
  166.              {"vsize", Dimension},
  167.              {"hoffset", Dimension},
  168.              {"voffset", Dimension},
  169.              {"hscale", Number},
  170.              {"vscale", Number}*/
  171.  
  172.  
  173. };
  174.  
  175. #define NKEYS (sizeof(KeyTab)/sizeof(KeyTab[0]))
  176.  
  177.  
  178. #ifdef __riscos
  179. #ifdef LJ
  180.  
  181. /* Compare two strings, ignoring case;
  182.    s1 pointer to null-terminated keyword, s2 pointer to parseline;
  183.    returns (if successful) pointer to character following keyword in s2 */
  184. bool StrCompare(char *s1, char *s2, char **end)
  185. {
  186.   char *a,*b;
  187.  
  188.   a = s1; b = s2;
  189.   while (*a != '\0') {
  190.     if (tolower(*a) != tolower(*b)) return(_FALSE);
  191.     a++; b++;
  192.   }
  193.   *end = b; return(_TRUE);
  194. }
  195.  
  196. /* Read <number> integer values from string and store results in <result>. Returns number
  197.    of arguments actually read, end = pointer to char following last number */
  198. int ParseNumbers(char *str, int *result, int number, char **end)
  199. {
  200.   char *s;
  201.   int count=0;
  202.  
  203.   s = str;
  204.   while ((*s != '\0') && (count < number))
  205.   {
  206.     while ((*s == ' ') || (*s == ',') || (*s == '=')) s++;
  207.     if (*s != '\0')
  208.     {
  209.       result[count++] = strtod(s,&s);
  210.     }
  211.   }
  212.   while ((*s == ' ') || (*s == ',') || (*s == '=')) s++;
  213.   *end = s; return(count);
  214. }
  215.  
  216.  
  217. /* Diagram commands are parsed separately since the format varies from the one
  218.    used by the other special commands */
  219. bool ParseDiagram(char *str)
  220. {
  221.   diagtrafo dt;
  222.   char *s,*sh;
  223.   char diagname[STRSIZE];
  224.   int results[4],no;
  225.  
  226.   s = str;
  227.   while (*s == ' ') s++;
  228.   if ((StrCompare("drawfile",s,&s)) || (StrCompare("DVIview_diagram",s,&s)))
  229.   {
  230.     if (printdiag == _FALSE) {return(_TRUE);} /* it's a diagram, but don't print */
  231.     while ((*s == ' ') || (*s == '=')) s++; /* space or '=' separates keyword/keyval */
  232.     if (*s == '\0')
  233.     {
  234.       printf("No filename given for \\special-diagram!\n"); return(_TRUE);
  235.     }
  236.     sh = diagname;
  237.     while ((*s != ' ') && (*s != ',') && (*s != '\0')) *sh++ = *s++;
  238.     *sh = '\0';
  239.     /* Set up default values */
  240.     dt.scalex = 100; dt.scaley = 100;
  241.     dt.cropl = 0; dt.cropb = 0; dt.cropr = 0; dt.cropt = 0;
  242.     while (*s != '\0')
  243.     {
  244.       while ((*s == ' ') || (*s == ',')) s++;
  245.       if (*s != '\0')
  246.       {
  247.         if (StrCompare("scale",s,&s))
  248.         {
  249.           if ((no = ParseNumbers(s,results,2,&s)) != 2)
  250.           {
  251.             printf("Too few arguments (%d) given for <scale> - ignored.\n",no);
  252.           }
  253.           dt.scalex = results[0]; dt.scaley = results[1];
  254.         }
  255.         else if (StrCompare("crop",s,&s))
  256.         {
  257.           if ((no = ParseNumbers(s,results,4,&s)) != 4)
  258.           {
  259.             printf("Too few arguments (%d) given for <crop> - ignored.\n",no);
  260.           }
  261.           dt.cropl = results[0]; dt.cropr = results[1];
  262.           dt.cropt = results[2]; dt.cropb = results[3];
  263.         }
  264.         else
  265.         {
  266.           printf("Bad \\special keyword - <%s> ignored\n",s);
  267.           /* skip over this word */
  268.           while ((*s != ' ') && (*s != ',') && (*s != '=') && (*s != '\0')) s++;
  269.         }
  270.       }
  271.     }
  272.     /* printf("Diagram: %s, scale %d %d, crop %d %d %d %d\n",diagname,dt.scalex,dt.scaley,dt.cropl,dt.cropb,dt.cropr,dt.cropt);*/
  273.     diagram(diagname,&dt);
  274.     return(_TRUE);
  275.   }
  276.   else return(_FALSE);
  277. }
  278. #endif
  279. #endif
  280.  
  281.  
  282. void
  283. DoSpecial(char *str, int n )
  284. /* interpret a \special command, made up of keyword=value pairs */
  285. {
  286.   char    spbuf[STRSIZE], xs[STRSIZE], ys[STRSIZE];
  287.   char    *sf = NULL;
  288.   float   x,y;
  289.   long4     x_pos, y_pos;
  290.   KeyWord k;
  291.   int     i, j, j1;
  292.   static int   GrayScale=10, Pattern=1;
  293.   static bool  GrayFill=_TRUE;
  294.   static long4  p_x[80], p_y[80];
  295.  
  296.   str[n] = '\0';
  297.   spbuf[0] = '\0';
  298.  
  299.   SetPosn(h, v);
  300.   #ifdef __riscos
  301.   #ifdef LJ
  302.   if (ParseDiagram(str)) return;
  303.   #endif
  304.   #endif
  305.   while ( (str = GetKeyStr(str, &k)) != NULL ) {
  306.     /* get all keyword-value pairs */
  307.     /* for compatibility, single words are taken as file names */
  308.     if ( k.vt == None && access(k.Key, 0) == 0) {
  309.         if ( sf )
  310.             Warning("More than one \\special file name given. %s ignored", sf);
  311.         (void) strcpy(spbuf, k.Key);
  312.         sf = spbuf;
  313. /*
  314.         for (j = 1; ((sf[j]=='/' ? sf[j]='\\':sf[j]) != '\0'); j++);
  315. */
  316.     } else if ( GetKeyVal( &k, KeyTab, NKEYS, &i ) && i != -1 )
  317.         switch (i) {
  318.         case PSFILE:
  319.         case HPFILE:
  320.             if ( sf )
  321.                 Warning("More than one \\special file name given. %s ignored",
  322.                             sf);
  323.             (void) strcpy(spbuf, k.Val);
  324.             sf = spbuf;
  325. /*
  326.             for (j=1; ((sf[j]=='/' ? sf[j]='\\':sf[j]) != '\0'); j++) ;
  327. */
  328.             break;
  329.         case ORIENTATION:
  330. #ifdef IBM3812
  331.             if ((k.v.i >= 0) && (k.v.i < 4)) {
  332.                 last_ry = UNKNOWN;
  333.                 sprintf(PMPformat, "\322%c", (unsigned char)k.v.i);
  334.                 PMPout(2, PMPformat);
  335.         if (k.v.i == 1) Landscape = _TRUE;
  336.         else if (k.v.i == 0) Landscape = _FALSE;
  337. #endif
  338. #ifdef LJ
  339.             if ((k.v.i >= 0) && (k.v.i < 2)) {
  340.                 last_ry = UNKNOWN;
  341.                 EMIT(EMTO, "\033&l%dO\033*rF", (unsigned char)k.v.i); EMFLUSH;
  342. #endif
  343.             } else
  344.                 Warning( "Invalid orientation (%d)given; ignored.", k.v.i);
  345.             break;
  346.         case RESETPOINTS:
  347.             (void) strcpy(spbuf, k.Val);
  348.  
  349.             sf = NULL;
  350.             break;
  351.  
  352.         case DEFPOINT:
  353.           (void) strcpy(spbuf, k.Val);
  354.            i=sscanf(spbuf,"%d(%[^,],%s)",&j,xs,ys);
  355.            if (i>0) {
  356.               x_pos=h; y_pos=v;
  357.               if (i>1) {
  358.                   if (sscanf(xs,"%fpt",&x)>0) {
  359.                      fprintf(ERR_STREAM,"x = %f\n",x);
  360.                      x_pos = PT_TO_DVI(x);
  361.              }
  362.               }
  363.               if (i>2) {
  364.                   if (sscanf(ys,"%fpt",&y)>0) {
  365.                      fprintf(ERR_STREAM,"y = %f\n",y);
  366.                      y_pos = PT_TO_DVI(y);
  367.                 }
  368.               }
  369.               p_x[j]=x_pos;
  370.               p_y[j]=y_pos;
  371.            } else
  372.              Warning("invalid point definition\n");
  373.  
  374.            sf = NULL;
  375.            break;
  376.  
  377.         case FILL:
  378.           (void) strcpy(spbuf, k.Val);
  379.            i=sscanf(spbuf,"%d/%d %s",&j,&j1,xs);
  380.            if (i>1) {
  381. #ifdef LJ
  382.               SetPosn(p_x[j], p_y[j]);
  383.               x_pos = (long4)PIXROUND(p_x[j1]-p_x[j], hconv);
  384.               y_pos = (long4)PIXROUND(p_y[j1]-p_y[j], vconv);
  385.               if (labs(x_pos)<labs(y_pos)) x_pos=x_pos+3;
  386.               else                         y_pos=y_pos+3;
  387.               if (GrayFill) {
  388.         EMIT(EMTO, "\033*c%lda%ldb%dg2P", (long)x_pos, (long)y_pos, GrayScale); EMFLUSH;
  389.               } else {
  390.         EMIT(EMTO, "\033*c%lda%ldb%dg3P", (long)x_pos, (long)y_pos, Pattern); EMFLUSH;
  391.               }
  392.               last_ry = UNKNOWN;
  393. #endif
  394.            }
  395.            break;
  396.         case GRAY:
  397.             if ((k.v.i >= 0) && (k.v.i < 101)) {
  398.                 GrayScale = k.v.i;
  399.                 GrayFill = _TRUE;
  400.             } else
  401.                 Warning( "Invalid gray scale (%d) given; ignored.", k.v.i);
  402.             break;
  403.         case PATTERN:
  404.             if ((k.v.i >= 0) && (k.v.i < 7)) {
  405.                 Pattern = k.v.i;
  406.                 GrayFill = _FALSE;
  407.             } else
  408.                 Warning( "Invalid pattern (%d) given; ignored.", k.v.i);
  409.             break;
  410.         default:
  411.             Warning("Can't handle %s=%s command; ignored.", k.Key, k.Val);
  412.             break;
  413.         }
  414.     else
  415.         Warning("Invalid keyword or value in \\special - <%s> ignored", k.Key);
  416.   }
  417.   if ( sf ) {
  418.     last_ry = UNKNOWN;
  419. #ifdef IBM3812
  420.     PMPflush;
  421. #endif
  422.     if (i==HPFILE)
  423.       CopyHPFile( sf );
  424.     else
  425.       CopyFile( sf );
  426.   }
  427. }
  428.  
  429.  
  430. /*-->GetKeyStr*/
  431. /**********************************************************************/
  432. /*****************************  GetKeyStr  ****************************/
  433. /**********************************************************************/
  434. /* extract first keyword-value pair from string (value part may be null)
  435.  * return pointer to remainder of string
  436.  * return NULL if none found
  437.  */
  438. char    KeyStr[STRSIZE];
  439. char    ValStr[STRSIZE];
  440. char
  441. *GetKeyStr(char *str, KeyWord *kw )
  442. {
  443.     char    *s, *k, *v, t;
  444.     if ( !str )
  445.         return( NULL );
  446.     for ( s = str; *s == ' '; s++)
  447.         ;          /* skip over blanks */
  448.     if ( *s == '\0' )
  449.         return( NULL );
  450.     for ( k = KeyStr; /* extract keyword portion */
  451.     *s != ' ' && *s != '\0' && *s != '=';
  452.         *k++ = *s++)
  453.         ;
  454.     *k = '\0';
  455.     kw->Key = KeyStr;
  456.     kw->Val = v = NULL;
  457.     kw->vt = None;
  458.     for ( ; *s == ' '; s++)
  459.         ;            /* skip over blanks */
  460.     if ( *s != '=' )         /* look for "=" */
  461.         return( s );
  462.     for ( s++; *s == ' '; s++);      /* skip over blanks */
  463.     if ( *s == '\'' || *s == '\"' )  /* get string delimiter */
  464.         t = *s++;
  465.     else
  466.         t = ' ';
  467.     for ( v = ValStr; /* copy value portion up to delim */
  468.     *s != t && *s != '\0';
  469.         *v++ = *s++)
  470.         ;
  471.     if ( t != ' ' && *s == t )
  472.         s++;
  473.     *v = '\0';
  474.     kw->Val = ValStr;
  475.     kw->vt = String;
  476.     return( s );
  477. }
  478.  
  479.  
  480. /*-->GetKeyVal*/
  481. /**********************************************************************/
  482. /*****************************  GetKeyVal  ****************************/
  483. /**********************************************************************/
  484. /* get next keyword-value pair decode value according to table entry  */
  485. bool
  486. GetKeyVal(KeyWord *kw, KeyDesc tab[], int nt, int *tno)
  487. {
  488.     int     i;
  489.     char    c = '\0';
  490.     *tno = -1;
  491.     for (i = 0; i < nt; i++)
  492.         if ( IsSame(kw->Key, tab[i].Entry) ) {
  493.             *tno = i;
  494.             switch ( tab[i].Typ ) {
  495.             case None:
  496.                 if ( kw->vt != None )
  497.                     return( _FALSE );
  498.                 break;
  499.             case String:
  500.                 if ( kw->vt != String )
  501.                     return( _FALSE );
  502.                 break;
  503.             case Integer:
  504.                 if ( kw->vt != String )
  505.                     return( _FALSE );
  506.                 if ( sscanf(kw->Val, "%d%c",
  507.                     &(kw->v.i), &c) != 1
  508.                      || c != '\0' )
  509.                     return( _FALSE );
  510.                 break;
  511. /*              case Number:
  512.  *              case Dimension:
  513.  *                  if( kw->vt != String ) return( _FALSE );
  514.  *                  if( sscanf(kw->Val,"%f%c",
  515.  *                     &(kw->v.n), &c) != 1
  516.  *                  || c != '\0' ) return( _FALSE );
  517.  *                  break;
  518.  */
  519.             }
  520.             kw->vt = tab[i].Typ;
  521.             return( _TRUE );
  522.         }
  523.     return( _TRUE );
  524. }
  525.  
  526.  
  527.  
  528. /*-->IsSame*/
  529. /**********************************************************************/
  530. /*******************************  IsSame  *****************************/
  531. /**********************************************************************/
  532. bool                  /* compare strings, ignore case */
  533. IsSame(char *a, char *b)
  534. {
  535.     char *x, *y;
  536.     x = a;
  537.     y = b;
  538.     for ( ; *a != '\0'; a++,b++)
  539.         if ( tolower(*a) != tolower(*b) )
  540.             return( _FALSE );
  541.     return( *x == *y ? _TRUE : _FALSE );
  542. }
  543.  
  544.  
  545.  
  546.  
  547. /*-->FindPostAmblePtr*/
  548. /**********************************************************************/
  549. /************************  FindPostAmblePtr  **************************/
  550. /**********************************************************************/
  551. void
  552. FindPostAmblePtr(long4 *postambleptr)
  553. /* this routine will move to the end of the file and find the start
  554.     of the postamble */
  555. {
  556.     long4    i;
  557.     FSEEK (dvifp,  0l, SEEK_END);   /* goto end of file */
  558.     *postambleptr = FTELL (dvifp) - 4;
  559.     FSEEK (dvifp, *postambleptr, SEEK_SET);
  560.     while (_TRUE) {
  561.         FSEEK (dvifp, --(*postambleptr), SEEK_SET);
  562.         if (((i = NoSignExtend(dvifp, 1)) != 223) &&
  563.             (i != DVIFORMAT))
  564.             Fatal ("Bad end of DVI file");
  565.         if (i == DVIFORMAT)
  566.             break;
  567.     }
  568.     FSEEK (dvifp, (*postambleptr) - 4, SEEK_SET);
  569.     (*postambleptr) = NoSignExtend(dvifp, 4);
  570.     FSEEK (dvifp, *postambleptr, SEEK_SET);
  571. }
  572.  
  573.  
  574. unsigned char
  575. skip_specials(long4 *pkloc )
  576. {
  577.     long4    i, j;
  578.     register unsigned char  flag_byte;
  579.     do {
  580.     flag_byte = (unsigned char) NoSignExtend(pxlfp, 1);
  581. /*
  582. fprintf(ERR_STREAM,"flagbyte = %d, pkloc=%ld\n",(int)flag_byte,(long)*pkloc);
  583. */
  584.  
  585.     (*pkloc) ++;
  586.     if (flag_byte  >= 240)
  587.         switch (flag_byte) {
  588.         case 240:
  589.         case 241:
  590.         case 242:
  591.         case 243 : {
  592.             i = 0 ;
  593.             for (j = 240; j <= (long4)flag_byte; j++) {
  594.                 i = 256 * i + NoSignExtend(pxlfp, 1) ;
  595.                 (*pkloc) ++;
  596.             }
  597.             for (j = 1; j <= i; j++) {
  598.                 (void) NoSignExtend(pxlfp, 1) ;
  599.                 (*pkloc) ++;
  600.             }
  601.             break;
  602.         }
  603.         case 244 : {
  604.             i = NoSignExtend(pxlfp, 4);
  605.             (*pkloc) += 4;
  606.             break;
  607.         }
  608.         case 245 :
  609.             break;
  610.         case 246 :
  611.             break ;
  612.         case 247:
  613.         case 248:
  614.         case 249:
  615.         case 250:
  616.         case 251:
  617.         case 252:
  618.         case 253:
  619.         case 254:
  620.         case 255: {
  621.             Fatal("Unexpected flagbyte %d!\n",
  622.                  (int)flag_byte) ;
  623.             }
  624.         }
  625.     } while (!((flag_byte < 240) || (flag_byte == PK_POST))) ;
  626.     return(flag_byte);
  627. }
  628.  
  629.  
  630. /*-->ReadPostAmble*/
  631. /**********************************************************************/
  632. /**************************  ReadPostAmble  ***************************/
  633. /**********************************************************************/
  634. /***********************************************************************
  635.     This  routine  is  used  to  read  in  the  postamble  values.    It
  636.     initializes the magnification and checks  the stack height prior  to
  637.     starting printing the document.
  638. ***********************************************************************/
  639. void
  640. ReadPostAmble(bool load)
  641. {
  642.     FindPostAmblePtr (&postambleptr);
  643.     if (NoSignExtend(dvifp, 1) != POST)
  644.         Fatal ("POST missing at head of postamble");
  645. #ifdef DEBUG
  646.     if (Debug)
  647.         fprintf(ERR_STREAM,"got POST command\n");
  648. #endif
  649.     ppagep = NoSignExtend(dvifp, 4);
  650.     num = NoSignExtend(dvifp, 4);
  651.     den = NoSignExtend(dvifp, 4);
  652.     mag = NoSignExtend(dvifp, 4);
  653.     if ( usermag > 0 && usermag != mag )
  654.         Warning("DVI magnification of %ld over-ridden by user (%ld)",
  655.                      (long)mag, (long)usermag );
  656.     if ( usermag > 0 )
  657.         mag = usermag;
  658.     hconv = DoConv(num, den, hconvRESOLUTION);
  659.     vconv = DoConv(num, den, vconvRESOLUTION);
  660.     (void) NoSignExtend(dvifp, 4);   /* height-plus-depth of tallest page */
  661.     (void) NoSignExtend(dvifp, 4);   /* width of widest page */
  662.     if (NoSignExtend(dvifp, 2) >= STACK_SIZE)
  663.         Fatal ("Stack size is too small");
  664.     (void) NoSignExtend(dvifp, 2);   /* this reads the number of pages in */
  665.                      /* the DVI file */
  666. #ifdef DEBUG
  667.     if (Debug)
  668.         fprintf(ERR_STREAM,"now reading font defs");
  669. #endif
  670.     if (load)
  671.         GetFontDef ();
  672. }
  673.  
  674.  
  675.  
  676. #ifdef IBM3812
  677. /*-->PMPLine*/
  678. /**********************************************************************/
  679. /*****************************  PMPLine  ******************************/
  680. /**********************************************************************/
  681. void       /* drawing lines on the 3812 using PMP vector commands */
  682. PMPLine(int w, int y, int x)
  683. {
  684.  
  685.     if ((w == 0) || ((x == 0) && (y == 0)))
  686.         return;
  687.  
  688. /*
  689. fprintf(ERR_STREAM,"w=%d / %d - %d, y=%d / %d - %d, x=%d / %d - %d\n",
  690.         w,(char)(w & 0xff),(int)((signed_char)(w & 0xff)),
  691.         y,(char)(y & 0xff),(int)((signed_char)(y & 0xff)),
  692.         x,(char)(x & 0xff),(int)((signed_char)(x & 0xff)));
  693. */
  694.  
  695.     if ( (((signed_char)(x & 0xff)) == x ) &&
  696.         ( ((signed_char)(y & 0xff)) == y ) ) {
  697.         PMPcont(6);
  698.         PMPout(1, "\370");
  699.         EMITWORD(3);      /* length of vector */
  700.         PMPoutC((unsigned char)(0x80 | 0x00 | (unsigned char) w));
  701.         PMPoutC((signed_char)(y & 0xff));
  702.         PMPoutC((signed_char)(x & 0xff));
  703. /*
  704.         fprintf(ERR_STREAM,"F8 00 03: w=%d, x=%d(%d-%.2X), y=%d(%d-%.2X),\n",
  705.         w,x,(char)(x & 0xff),(signed_char)(x & 0xff),
  706.           y,(char)(y & 0xff),(signed_char)(y & 0xff));
  707. */
  708.  
  709.     } else {
  710.         PMPcont(8);
  711.         PMPout(1, "\370");
  712.         EMITWORD(4 + 1);      /* length of vector */
  713.         PMPoutC((unsigned char)(0xC0 | 0x00 | (unsigned char) w));
  714.         EMITWORD(y);
  715.         EMITWORD(x);
  716. /*
  717.         fprintf(ERR_STREAM,"F8 00 05: w=%d, x=%d, y=%d,\n", w,x,y);
  718. */
  719.     }
  720. }
  721.  
  722.  
  723. #endif
  724. /*-->SetRule*/
  725. /**********************************************************************/
  726. /*****************************  SetRule  ******************************/
  727. /**********************************************************************/
  728. void                   /*   this routine will draw a rule */
  729. SetRule(long4 a, long4 b, int Set)
  730. {
  731.     long4    xx, yy;
  732. #ifdef IBM3812
  733.     short   hor_offset, vert_offset, ll;
  734. #endif
  735.     if ( a > 0 && b > 0 ) {
  736.         SetPosn(h, v);             /* lower left corner */
  737.         xx = (long4)PIXROUND(b, hconv);     /* width */
  738.         yy = (long4)PIXROUND(a, vconv);     /* height */
  739.  
  740. #ifdef DEBUG
  741.         if (Debug)
  742.             fprintf(ERR_STREAM,"Rule xx=%ld, yy=%ld\n", (long)xx, (long)yy);
  743. #endif
  744.  
  745. #ifdef IBM3812
  746.         hor_offset  = (short)(last_ry - yy);
  747.         if (hor_offset < 0) yy += hor_offset;
  748.         if (last_rx < 0) xx += last_rx;
  749.  
  750.         if (Landscape) {
  751.           if (last_ry > MAX_PAGE_WIDTH) yy += MAX_PAGE_WIDTH-last_ry;
  752.           hor_offset  = (short)(MAX_PAGE_HEIGHT - (last_rx + xx));
  753.         } else {
  754.           if (last_ry > MAX_PAGE_HEIGHT) yy += MAX_PAGE_HEIGHT-last_ry;
  755.           hor_offset  = (short)(MAX_PAGE_WIDTH - (last_rx + xx));
  756.         }
  757.         if (hor_offset < 0) xx += hor_offset;
  758.  
  759.         if ((xx > 31) && (yy > 31)) {
  760. /*
  761.  *   fill area by multiple lines  (kind of a mess)
  762.  *   process for simplicity always horizontally
  763.  */
  764.  
  765. /* fprintf(ERR_STREAM, "large box: w=%d, x=%d, y=%d\n",(int)yy,(int)xx,0);*/
  766.  
  767.             hor_offset  = HOR_HALF(30);
  768.             MoveHor(hor_offset);
  769.             vert_offset = VERT_HALF(30);
  770.             MoveVert(-vert_offset);
  771.             ll = (short)xx - 30;
  772.  
  773.             for (; yy > 30; yy -= 30) {
  774.                 PMPLine(30, 0, ll);
  775.                 MoveHor(-ll);
  776.                 MoveVert(-30);
  777.             }
  778.  
  779.             hor_offset  = -hor_offset     + HOR_HALF(yy);
  780.             MoveHor(hor_offset);
  781.             vert_offset = (vert_offset - 30) + VERT_HALF(yy);
  782.             MoveVert(-vert_offset);
  783.  
  784.             PMPLine((int)yy, 0, (int)(xx - yy));
  785.  
  786.         } else if ( (yy < xx) && (xx > 0) ) {
  787.  
  788. /* fprintf(ERR_STREAM, "hori rule: w=%d, x=%d, y=%d\n",(int)yy,(int)(xx-yy),0);*/
  789.  
  790.             hor_offset  = HOR_HALF(yy);
  791.             vert_offset = VERT_HALF(yy);
  792.  
  793.             MoveHor(hor_offset);
  794.             MoveVert(-vert_offset);
  795.  
  796.             PMPLine((int)yy, 0, (int)(xx - yy));
  797.         } else if ( (xx < yy) && (yy > 0)) {
  798.  
  799.             hor_offset  = HOR_HALF(xx);
  800.             vert_offset = VERT_HALF(xx);
  801. /*
  802.  fprintf(ERR_STREAM, "move: x=%d, y=%d\n",hor_offset,-vert_offset);
  803.  fprintf(ERR_STREAM, "vert rule: w=%d, x=%d, y=%d\n",(int)xx,0,(int)-(yy-xx));
  804. */
  805.             MoveHor(hor_offset);
  806.             MoveVert(-vert_offset);
  807.  
  808.             PMPLine((int)xx, (int)-(yy - xx), 0);
  809.         } else if (xx == yy) {
  810.             short     y0;  /* small square box!! */
  811.  
  812.             y0 = (short)yy / 2;
  813.             hor_offset  = HOR_HALF(y0);
  814.             MoveHor(hor_offset);
  815.             vert_offset = VERT_HALF(y0);
  816.             MoveVert(-vert_offset);
  817.             ll = (short)xx - y0;
  818.  
  819.             PMPLine((int)y0, 0, ll);
  820.  
  821.             hor_offset  = -(ll + hor_offset);
  822.             vert_offset = (y0 - vert_offset);
  823.  
  824.             yy -= (long4)y0;
  825.             hor_offset  += HOR_HALF(yy);
  826.             MoveHor(hor_offset);
  827.             vert_offset += VERT_HALF(yy);
  828.             MoveVert(-vert_offset);
  829.  
  830.             PMPLine((int)yy, 0, (int)xx - yy);
  831.         }
  832. #endif
  833. #ifdef LJ
  834.     if (last_ry + 1 < yy) yy = last_ry + 1;
  835.     if (last_rx < 0) xx += last_rx;
  836.  
  837.     if (((int)pgsiz_dots >0) && ((int)last_ry > (int)pgsiz_dots))
  838.       yy += (long4)pgsiz_dots - (long4)last_ry;
  839.  
  840.         if ((yy>0) && (xx>0)) {
  841.                 EMIT(EMTO, "\033*p-%ldY\033*c%lda%ldbP", (long)yy - 1, (long)xx, (long)yy);
  842.                 EMFLUSH;
  843.         }
  844. #endif
  845.         last_ry = UNKNOWN;       /* next time full positioning */
  846.     }
  847.     if (Set)
  848.         h += b;
  849. }
  850.  
  851.  
  852. /*-->FormFeed*/
  853. /**********************************************************************/
  854. /*****************************  FormFeed ******************************/
  855. /**********************************************************************/
  856. void
  857. FormFeed(void)
  858. {
  859.  
  860. #ifdef IBM3812
  861.     unsigned short pages;
  862.     if ( (ndone == 0) && (FirstAlternate)){
  863.         for (pages = 1; pages < ncopies; pages++) {
  864.             PMPout(2, "\321\300"); /* PMP-command xD1C0 */
  865.         }
  866.         PMPout(2, "\321\100"); /* PMP-command xD140 */
  867.     } else {
  868.         for (pages = 1; pages < ncopies; pages++){
  869.             PMPout(2, "\321\200"); /* PMP-command xD180 */
  870.         }
  871.         PMPout(2, "\321\0"); /* PMP-command xD100 */
  872.     }
  873. #endif
  874. #ifdef LJ
  875.     EMITC('\f');
  876. #endif
  877. }
  878.